package selenium;

import org.testng.annotations.Test;
import selenium.model.Film;
import selenium.model.User;
import selenium.pages.TestBase;

import static org.junit.Assert.assertTrue;

public class FilmAddDelete extends TestBase {

    @Test
    public void testFilmAdd() throws Exception {
        // Log in
        User user = new User("editor", "1");
        app.getUserHelper().loginAs(user);
        assertTrue(app.getUserHelper().isLoggedInAs(user));
        app.getNavigationHelper().gotoInternalMainPage();
        app.getNavigationHelper().gotoAddMoviePage();


        // Data for form filling
        Film film = new Film();
        film.setName("3 million square kilometers");
        film.setAka("Exceptional fire on the water");
        film.setYear("2013");
        film.setDuration("94");
        film.setRating("7");
        film.setFormats("DVD, Blue-ray");
        film.setLoanname("2014-01-01");
        film.setLoandate("2014-01-01");
        film.setCover("C:\\Users\\Павел\\Desktop\\trees23.jpg");
        film.setTrailer("http://www.youtube.com/watch?v=LjwTCKYsNlE&list=TLS70pCxyRnxzTqBKSruwXjUhKLjwaXQiB");
        film.setNotes("notes");
        film.setTaglines("\"Death doesn't take no for an answer.\"\n" +
                "\"A Hero Will Rise\"\n" +
                "\"Ice cold. Hot wired.\"\n" +
                "\"Think you're alone? Think again.\"\n" +
                "\"Nobody ever grows up quite like they imagined.\"\n" +
                "\"Some memories are best forgotten.\"\n" +
                "\"From gentle to mental.\"\n" +
                "\"Expect the impossible again\"\n" +
                "\"They have a plan...but not a clue.\"\n" +
                "\"Meet the Marquis de Sade. The pleasure is all his.\"\n" +
                "\"Throw the ball. Catch the girl. Keep it simple.\"\n" +
                "\"No mercy. No shame. No sequel.\"\n" +
                "\"Trust a few. Fear the rest.\"");
        film.setLanguages("English\nFrench");
        film.setPlotoutline("The human city of Zion defends itself against the massive invasion of the machines as Neo fights to end the war at another front while also opposing the rogue Agent Smith.");

        // Add film
        app.getFilmHelper().createFilm(film);
        app.getFilmHelper().compareFilm(film);
        app.getUserHelper().logout();
    }

    @Test
    public void testFilmAddError() throws Exception {
        // Add film object
        Film film = new Film();
        film.setName("3 million square kilometers");

        // Log in
        User user = new User("editor", "1");
        app.getUserHelper().loginAs(user);
        assertTrue(app.getUserHelper().isLoggedInAs(user));

        // Fill form with wrong values and check if the same page stays
        app.getNavigationHelper().gotoInternalMainPage();
        app.getNavigationHelper().gotoAddMoviePage();
        app.getFilmHelper().createFilm(film);
        app.getFilmHelper().addMoviePageLoaded();
        app.getUserHelper().logout();

    }

    @Test
    public void testFilmDelete() throws Exception {
        // Initialize film object
        Film film = new Film();
        film.setName("3 million square kilometers");

        // Log in
        User user = new User("editor", "1");
        app.getUserHelper().loginAs(user);
        assertTrue(app.getUserHelper().isLoggedInAs(user));

        app.getNavigationHelper().gotoInternalMainPage();
        app.getFilmHelper().openFilmByName(film.getName());
        app.getFilmHelper().deleteFilm();
        app.getFilmHelper().checkFilmAbsent(film.getName());
        app.getUserHelper().logout();
    }

}